define(["jquery","bbcare"],function($,$bb){
	var servers = {};
	var URL = $bb.baseUrl("followapp");

    /**
     * 根据手机号、姓名查询患者信息(量表列表页面需要)
     */
    servers.ajaxSearch = function(params,callback,arg){
        $bb.ajax({
            url: URL + "ctrl/ptmanage/patientQueryByPhoneNum",
            data: JSON.stringify({
                data: params
            }),
            success: function (data) {
                if(data.success){
                    callback(data.data,arg);
                }else{
                    $bb.toastShow(data.msg ? data.msg : "根据手机号码或姓名搜索出错！");
                }
            }
        })
    };

    /**
     * 获取选择的患者的基本信息(量表列表页面需要)
     */
    servers.getInfo = function(list,userId){
        for (var i = 0; i < list.length; i++) {
            if( list[i].userId == userId ){
                return list[i];
            }
        }
    }

    /**
     * 查询用户信息(量表详情页面需要)
     */
    servers.ajaxUserMassage = function(params,callback){
        $bb.ajax({
            url: URL + "service/evaluation/queryUserMassage",
            data:JSON.stringify({
                data : {
                    "channelType":"2",
                    "queueUserId":params.userId,
                }
            }),
            success: function(data){
                if(data.success){
                    callback(data.data,params);
                }else{
                    $bb.toastShow(data.msg ? data.msg : "查询用户信息出错！");
                }   
            }
        });
    }

    /**
     * 查询评估量表问卷(量表详情页面需要)
     */
    servers.ajaxPostion = function(params,callback){
        $bb.ajax({
            url: URL + "service/evaluation/getPostion",
            data:JSON.stringify({
                data : {
                    "evaluationType":params.evaluationType,
                    "queueUserId":params.userId
                }
            }),
            success: function(data){
                if(data.success){
                    callback(data.data,params);
                }else{
                    $bb.toastShow(data.msg ? data.msg : "查询评估量表问卷出错！");
                }   
            }
        });
    }

    /**
     * 评估提交(量表详情页面需要)
     */
    servers.ajaxSubmit = function(params,callback){
        $bb.ajax({
            url: URL + "service/evaluation/submitGetScore",
            data:JSON.stringify({
                data : params
            }),
            success: function(data){
                if(data.success){
                    callback(data.data);
                }else{
                    $bb.toastShow(data.msg ? data.msg : "评估提交出错！");
                }
            }
        });
    }

    /**
     * 查询用户评估信息(量表报告页面需要)
     */
    servers.ajaxRecordlist = function(params,callback){
        $bb.ajax({
            url: URL + "service/evaluation/recordlist",
            data: JSON.stringify({
                data: {
                    "channelType":"2",
                    "evaluationType":params.evaluationType,
                    "queueUserId":params.userId,
                }
            }),
            success: function (data) {
                callback(data,params);
            }
        })
    }

    /**
     * 处理历史记录数据(量表报告页面需要)
     */
    servers.handleHistoryData = function(list){
        for (var i = 0; i < list.length; i++) {
            list[i].testAge = $bb.simple.formatAge(list[i].ageDay);
        }
        return list;
    }

    /**
     * 获取当前记录id的索引(量表报告页面需要)
     */
    servers.getRecordIndex = function(list,params){
        for (var i = 0; i < list.length; i++) {
            if( list[i].id == params.id ){
                return i;
            }
        }
        return 0;
    }

    /**
     * 请求评估详情 (量表报告页面需要)
     */
    servers.ajaxRecordDetail = function(params,callback){
        $bb.ajax({
            url: URL + "service/evaluation/getEvaluationDetail",
            data: JSON.stringify({
                data: {
                    "channelType":"2",
                    "evaluationType":params.evaluationType,
                    "recordId":params.id,
                }
            }),
            success: function (data) {
                callback(data.data,params);
            }
        });
    }

	return servers;
});